package com.one.common.view.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.one.common.R;
import com.one.common.utils.StringUtils;

/**
 * Author: zhulunjun
 * Email: zhulunjun@qq.com
 * CreateDate: 2019/11/4 15:03
 * Description：
 **/
public class OrderStateView extends LinearLayout {
    private View v1, v2, v3, vLine1, vLine2, vLine3, vLine4;
    private ImageView iv1, iv2, iv3;
    private TextView tv1, tv2, tv3;
    private TextView tvTime1, tvTime2, tvTime3;

    public OrderStateView(Context context) {
        super(context);
        init(context, null);
    }

    public OrderStateView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    private void init(Context context, @Nullable AttributeSet attrs) {
        if (attrs == null) {
            return;
        }
        LayoutInflater.from(context).inflate(R.layout.layout_order_state, this);
        v1 = findViewById(R.id.v_o_1);
        v2 = findViewById(R.id.v_o_2);
        v3 = findViewById(R.id.v_o_3);

        vLine1 = findViewById(R.id.v_line_1);
        vLine2 = findViewById(R.id.v_line_2);
        vLine3 = findViewById(R.id.v_line_3);
        vLine4 = findViewById(R.id.v_line_4);

        iv1 = findViewById(R.id.iv_o_1);
        iv2 = findViewById(R.id.iv_o_2);
        iv3 = findViewById(R.id.iv_o_3);

        tv1 = findViewById(R.id.tv_1);
        tv2 = findViewById(R.id.tv_2);
        tv3 = findViewById(R.id.tv_3);

        tvTime1 = findViewById(R.id.tv_time_1);
        tvTime2 = findViewById(R.id.tv_time_2);
        tvTime3 = findViewById(R.id.tv_time_3);

        setGravity(Gravity.CENTER);

    }

    public void setState(int index) {
        switch (index) {
            case 0:
                v1.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_9));
                v2.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_9));
                v3.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_9));

                vLine1.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));
                vLine2.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));
                vLine3.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));
                vLine4.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));

                iv1.setVisibility(GONE);
                iv2.setVisibility(GONE);
                iv3.setVisibility(GONE);

                tv1.setTextColor(getContext().getResources().getColor(R.color.gray));
                tv2.setTextColor(getContext().getResources().getColor(R.color.gray));
                tv3.setTextColor(getContext().getResources().getColor(R.color.gray));

                tvTime1.setVisibility(GONE);
                tvTime2.setVisibility(GONE);
                tvTime3.setVisibility(GONE);
                break;
            case 1:
                v1.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_green_9));
                v2.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_9));
                v3.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_9));

                vLine1.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));
                vLine2.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));
                vLine3.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));
                vLine4.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));

                iv1.setVisibility(VISIBLE);
                iv2.setVisibility(GONE);
                iv3.setVisibility(GONE);

                tv1.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tv2.setTextColor(getContext().getResources().getColor(R.color.gray));
                tv3.setTextColor(getContext().getResources().getColor(R.color.gray));

                tvTime1.setVisibility(VISIBLE);
                tvTime2.setVisibility(GONE);
                tvTime3.setVisibility(GONE);

                tvTime1.setTextColor(getContext().getResources().getColor(R.color.root_green));
                break;
            case 2:
                v1.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_green_9));
                v2.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_green_9));
                v3.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_9));

                vLine1.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));
                vLine2.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));
                vLine3.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));
                vLine4.setBackgroundColor(getContext().getResources().getColor(R.color.hint_cccccc));

                iv1.setVisibility(GONE);
                iv2.setVisibility(VISIBLE);
                iv3.setVisibility(GONE);

                tv1.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tv2.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tv3.setTextColor(getContext().getResources().getColor(R.color.gray));

                tvTime1.setVisibility(VISIBLE);
                tvTime2.setVisibility(VISIBLE);
                tvTime3.setVisibility(GONE);

                tvTime1.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tvTime2.setTextColor(getContext().getResources().getColor(R.color.root_green));
                break;
            case 3:
                v1.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_green_9));
                v2.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_green_9));
                v3.setBackground(getContext().getResources().getDrawable(R.drawable.shape_o_gray_green_9));

                vLine1.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));
                vLine2.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));
                vLine3.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));
                vLine4.setBackgroundColor(getContext().getResources().getColor(R.color.root_green));

                iv1.setVisibility(GONE);
                iv2.setVisibility(GONE);
                iv3.setVisibility(VISIBLE);

                tv1.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tv2.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tv3.setTextColor(getContext().getResources().getColor(R.color.root_green));

                tvTime1.setVisibility(VISIBLE);
                tvTime2.setVisibility(VISIBLE);
                tvTime3.setVisibility(VISIBLE);

                tvTime1.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tvTime2.setTextColor(getContext().getResources().getColor(R.color.root_green));
                tvTime3.setTextColor(getContext().getResources().getColor(R.color.root_green));
                break;
        }
    }

    public void setTime1(String time) {
        if (StringUtils.isNotBlank(time))
            tvTime1.setText(time);
    }


    public void setTime2(String time) {
        if (StringUtils.isNotBlank(time))
            tvTime2.setText(time);
    }


    public void setTime3(String time) {
        if (StringUtils.isNotBlank(time))
            tvTime3.setText(time);
    }
}
